package queue;

import array.Array;

public class ArrayQueue <E> implements Queue <E>{

	private Array<E> data;
	
	public ArrayQueue(int capacity) {
		data = new Array<E>(capacity);
	}
	
	public ArrayQueue() {
		data = new Array<E>();
	}

	@Override
	public void enqueue(E e) {
		//入队
		data.addLast(e);
	}

	@Override
	public E dequeue() {
		//出队
		return data.removeFirst();
	}

	@Override
	public E getFront() {
		return data.getFirst();
	}

	@Override
	public int getSize() {
		return data.getSize();
	}

	@Override
	public boolean isEmpty() {
		return data.isEmpty();
	}
	
	@Override
	public String toString() {
		StringBuilder res = new StringBuilder();
		res.append("ArrayQueue: size:"+data.getSize()+",capacity:"+data.getCapacity());
		res.append("front:[");
		for(int i = 0 ; i < data.getSize() ; i++) {
			res.append(data.get(i));
			if(i < data.getSize()-1) {
				res.append(",");
			}
		}
		res.append("]tail");
		return res.toString();
	}
}
